# -*- coding: utf-8 -*-



import  wx
import  os
import sys

from wx.lib.buttons import GenBitmapButton

from mainview import help
import wx.lib.ogl as ogl
from erview import ERD


# Our tool IDs:

id_SELECT  = 11001
id_LINE    = 11002
id_RECT    = 11003
id_ELLIPSE = 11004
id_TEXT    = 11005

class MainPanel(wx.Notebook):
    def __init__(self,parent, size =(21,21) ):
        wx.Notebook.__init__(self, parent, -1, size=size,
                         #style=
                         #wx.NB_TOP # | wx.NB_MULTILINE
                         #wx.NB_BOTTOM
                         #wx.NB_LEFT
                         #wx.NB_RIGHT
                         )
        win = help.Help(self)
        
        try:
            ogl.OGLInitialize()
            #erd = ERD.ERDWindow(self, None, parent)
            #self.AddPage(erd, u"ERD")
            #p1 = wx.Panel(parent, -1)
            #style=wx.SIMPLE_BORDER
            self.topPanel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
            self.selectIcon  = ToolPaletteIcon(self.topPanel, id_SELECT,
                                               "select", "Selection Tool")            
            self.lineIcon    = ToolPaletteIcon(self.topPanel, id_LINE,
                                               "line", "Line Tool")            
            self.rectIcon    = ToolPaletteIcon(self.topPanel, id_RECT,
                                               "rect", "Rectangle Tool")
            self.ellipseIcon = ToolPaletteIcon(self.topPanel, id_ELLIPSE,
                                               "ellipse", "Ellipse Tool")
            self.textIcon    = ToolPaletteIcon(self.topPanel, id_TEXT,
                                               "text", "Text Tool")
            """
            self.toolPalette = wx.BoxSizer(wx.VERTICAL)
            """
            toolSizer = wx.BoxSizer(wx.HORIZONTAL) #wx.GridSizer(0, 2, 5, 5)
            toolSizer.Add(self.selectIcon)
            
            toolSizer.Add((2, 2)) # Gap to make tool icons line up nicely.
            toolSizer.Add(self.lineIcon)
            
            toolSizer.Add(self.rectIcon)
            toolSizer.Add(self.ellipseIcon)
            toolSizer.Add(self.textIcon)
            
            topSizer = wx.BoxSizer(wx.VERTICAL)
            topSizer.Add(toolSizer, 0)
            
            self.drawPanel = ERD.ERDWindow(self.topPanel, None, parent)
            topSizer.Add(self.drawPanel, 1, wx.EXPAND)
            
            self.topPanel.SetAutoLayout(True)
            self.topPanel.SetSizer(topSizer)
            """
            self.SetSizeHints(250, 200)
            self.SetSize(wx.Size(600, 400))
            
            self.SetSizer(self.toolPalette)
            self.Fit()            
            """
            self.AddPage(self.topPanel, u"p1")   
            
            
        except Exception, e:
            print  e

        self.AddPage(win, u"Help")   
        
        

class ToolPaletteIcon(GenBitmapButton):
    """ An icon appearing in the tool palette area of our sketching window.

        Note that this is actually implemented as a wx.Bitmap rather
        than as a wx.Icon.  wx.Icon has a very specific meaning, and isn't
        appropriate for this more general use.
    """

    def __init__(self, parent, iconID, iconName, toolTip):
        """ Standard constructor.

            'parent'   is the parent window this icon will be part of.
            'iconID'   is the internal ID used for this icon.
            'iconName' is the name used for this icon.
            'toolTip'  is the tool tip text to show for this icon.

            The icon name is used to get the appropriate bitmap for this icon.
        """
        bmp = wx.Bitmap("images/" + iconName + "Icon.bmp", wx.BITMAP_TYPE_BMP)
        GenBitmapButton.__init__(self, parent, iconID, bmp, wx.DefaultPosition,
                                wx.Size(bmp.GetWidth(), bmp.GetHeight()))
        self.SetToolTip(wx.ToolTip(toolTip))

        self.iconID     = iconID
        self.iconName   = iconName
        self.isSelected = False


    def select(self):
        """ Select the icon.

            The icon's visual representation is updated appropriately.
        """
        if self.isSelected: return # Nothing to do!

        bmp = wx.Bitmap("images/" + self.iconName + "IconSel.bmp",
                       wx.BITMAP_TYPE_BMP)
        self.SetBitmapLabel(bmp)
        self.isSelected = True


    def deselect(self):
        """ Deselect the icon.

            The icon's visual representation is updated appropriately.
        """
        if not self.isSelected: return # Nothing to do!

        bmp = wx.Bitmap("images/" + self.iconName + "Icon.bmp",
                       wx.BITMAP_TYPE_BMP)
        self.SetBitmapLabel(bmp)
        self.isSelected = False        


